package me.znext.learn.android;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Feedback extends AppCompatActivity {
  private EditText feedbackEditText;
  private String feedbackPhone;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_feedback);

    this.setTitle("用户反馈");
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    new LeftMenu(this);
    feedbackEditText = (EditText) findViewById(R.id.feedbackEditText);
    feedbackPhone = this.getString(R.string.feedbackPhone);

    Button sendFeedbackButton = (Button) findViewById(R.id.sendFeedbackButton);
    assert sendFeedbackButton != null;
    sendFeedbackButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        sendFeedbackSms();
      }
    });
  }

  private void sendFeedbackSms() {
    SmsManager sms = SmsManager.getDefault();
    String message = String.valueOf(feedbackEditText.getText());
    sms.sendTextMessage(feedbackPhone, null, message, null, null);
    Notice.alert(this, "感谢您的反馈");
    feedbackEditText.setText("");
  }
}
